package 华为OD机试真题2023.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ13_统计差异值大于相似值二元组个数 {
    public static void main(String[] args) throws FileNotFoundException {
        MyUtil.START();
        Solution();
        //        Solution2();
        MyUtil.END();
    }

    static void Solution() throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/13.txt"));
        int N = in.nextInt();
        in.nextLine(); // 吸收回车
        String[] sArray = in.nextLine().split(" ");
        int[] weishu = new int[32];
        for (int i = 0; i < N; i++) {
            int num = Integer.parseInt(sArray[i]);
            int h = 0;
            while (num > 0) {
                num >>= 1;
                h++;
            }
            weishu[h]++;
        }
        int res = handle(N - 1);
        for (int i = 0; i < 32; i++) {
            if (weishu[i] > 1) {
                res -= handle(weishu[i] - 1);
            }
        }
        System.out.println(res);
    }

    static int handle(int x) {
        if (x == 1) return 1;
        return x + handle(x - 1);
    }

    static void Solution2() throws FileNotFoundException {
        Scanner sc = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/13.txt"));
        int n = sc.nextInt();
        int[] cnt = new int[32];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int h = 0;
            while (x > 0) {
                x /= 2;
                h++;
            }
            cnt[h]++;
            ans += (i + 1) - cnt[h];
        }
        System.out.println(ans);
    }
}
